<?php
/** UnivIS update script
 * Fetches content from UnivIS via PRG interface in XML and stores 
 * it into a mysql database
 */

require_once 'modules/generic_module.php';
$lecturesTruncated = false;

class LecturesModule extends GenericModule
{
    var $year;
    var $sem;

    function LecturesModule($module)
    {
	global $lecturesTruncated;

	$this->module = $module;
	$this->year = 2000;
	$this->sem  = 's';

	if (!$lecturesTruncated)
	{
	    $sql = 'TRUNCATE TABLE u_lecture_term';
	    mysql_query($sql);
	    $lecturesTruncated = true;
	}
    }

    function getUrl($uConf)
    {
	$semester = $this->year.$this->sem;
	$GLOBALS['semester'] = $semester;
	return $uConf['prg_url']
		. 'department='.$uConf['department']
		. '&search='.$this->module
		. '&show=xml'
		. '&sem='.$semester;
    }

    function hasMoreUrls()
    {
	$GLOBALS['semester'] = '';
	unset($GLOBALS['semester']);
	if ('w' == $this->sem) {
	    ++$this->year;
	    $this->sem = 's';
	} else {
	    $this->sem = 'w';
	}
	if ($this->year >= (date('Y')+1)) {
	    return false;
	}
	return true;
    }
}
?>